<html>

<body>

Type an SQL query in the following box:

<form method="get" ACTION="http://192.168.56.20/~cs143/query.php">
	
<textarea name="query" rows="8" cols="60"></textarea>
	<input type="submit" value="Submit">

</form>


<?php

	$query =$_GET["query"];
	
$db_connection = mysql_connect("localhost","cs143","");

	if(!$db_connection)

	{
	
		$errmsg= mysql_error($db_connection);

		print "Connection failed: $errmsg <br />";

		exit(1);

	}
	
else
	
{
		
mysql_select_db('CS143', $db_connection);

		$sanitized_name = mysql_real_escape_string($name, $db_connection);

		$query_to_issue = sprintf($query, $sanitized_name);

		$rs = mysql_query($query_to_issue, $db_connection);

		while($row = @(mysql_fetch_row($rs)))

		{
			
$comma_separated = implode(",", $row);

			print "$comma_separated <br />";  

		}

	}

	mysql_close($db_connection);

?>

</body>

</html>
